namespace Vanilla.UI
	
class DefaultTheme (Theme):
	override def DefaultSpacingFor (g as Gadget) as double:
		if g isa Menu:
			return 0
		elif g isa ButtonBar:
			return 0
		elif g isa Box:
			if (g as Box).DrawFrame:
				return 5
			else:
				return 0
		else:
			return 0
	
	override def DefaultFontFor (g as Gadget) as Font:
		if g isa Button.Label:
			return Font("Arial", 16)
		else:
			return Font()
	
	override def DefaultForegroundColourFor (g as Gadget) as Colour:
		return Colour(0.1,0.1,0.2)
	
	override def MouseOverChangesLookFor (g as Gadget) as bool:
		if g isa Label:
			return false
		elif g isa Button:
			return true
		elif g isa Window:
			return true
		elif g isa PanelItem:
			return true
		elif g isa Box:
			return false
		else:
			return true
	
	virtual def DrawGadget (g as Gadget, b as Brush):
		b.Colour = Colour.Red.Alpha(0.5)
		b.Draw(Rect(0,0,g.Rect.Width,g.Rect.Height))
		b.Fill()
		b.Colour = Colour.Black
		b.LineWidth = 3
		b.Draw(Rect(0,0,g.Rect.Width,g.Rect.Height))
		b.Stroke()
	
	virtual def DrawWindow (w as Window, b as Brush):
		// Draw background/fill
		gr = LinearGradient(0,0,0,w.Size.Height)
		
		if w.ContainsMouse:
			gr.Add(0, Colour(1, 1, 0, 0.9))
			gr.Add(13/w.Size.Height, Colour(1,0.8,0.35))
			gr.Add(1, Colour(0.8,0.8,0.5,0.75))
		else:
			gr.Add(0, Colour(0.75,0.75,0.75))
			gr.Add(1, Colour(1,1,1,0.5))
		
		
		b.Pattern = gr
		b.Draw(Rect(w.Size))
		b.Fill()
		
		// Draw resizer
		if w.CanResize:
			gr = LinearGradient(w.Size.Width-25, w.Size.Height-25, w.Size.Width, w.Size.Height)
			gr.Add(0.5, Colour(0,0,0,0))
			if w.BeingResized:
				gr.Add(1,Colour(0,0,0))
			else:
				gr.Add(1,Colour(0,0,0,0.5))
			b.Pattern = gr
			b.Draw(Rect(w.Size.Width-25,w.Size.Height-25, w.Size.Width, w.Size.Height))
			b.Fill()
		
		// Draw outline
		b.Colour = Colour.Black
		b.LineWidth = 3
		b.Draw(Rect(w.Size))
		b.Stroke()
	
	virtual def DrawMenuItem (m as MenuItem, b as Brush):
		if m.ContainsMouse:
			gr = LinearGradient(0,0,0,m.Size.Height)
			gr.Add(0,Colour(1,0.8,0.35,0.25))	
			gr.Add(0.5,Colour(1,0.8,0.35,0.5))
			gr.Add(1,Colour(1,0.8,0.35,0.25))
			
			b.Pattern = gr
			b.Draw(Rect(m.Size))
			b.Fill()
	
	virtual def DrawButton (g as Button, b as Brush):
		b.Draw(Rect(g.Size))
		
		if g.ContainsMouse:
			b.Colour = Colour.Green
		else:
			b.Colour = Colour.Green.Alpha(0.5)
		b.FillPreserve()
		
		b.Colour = Colour.Black
		b.Stroke()
		/*
		gr = LinearGradient(0,0,0,g.Rect.Height)
		gr.Add(0, Colour(1, 0.8, 0.35, 0.5))
		if g.ContainsMouse:
			gr.Add(0.5, Colour(0, 1, 1))
		else:
			gr.Add(0.5, Colour(0, 0.65, 0.65, 0.9))
		gr.Add(1, Colour(1, 0.8, 0.35, 0.5))
		
		b.Pattern = gr
		b.Draw(Rect(g.Size))
		b.Fill()
		b.Colour = Colour.Black
		b.LineWidth = 2
		b.Draw(Rect(g.Size))
		b.Stroke()
		*/
	
	virtual def DrawWindowCloseButton (g as Window.CloseButton, b as Brush):
		gr = LinearGradient(0,0,0,g.Size.Height)
		if g.ContainsMouse:
			gr.Add(0, Colour.Red)
			gr.Add(1, Colour(1,0,0,0.5))
		else:
			gr.Add(0, Colour(1,0,0,0.5))
			gr.Add(1, Colour(1,0,0,0))
		b.Pattern = gr
		b.Draw(Rect(g.Size))
		b.Fill()
		
		if g.ContainsMouse:
			b.Colour = Colour.Black
			b.LineWidth = 2
			b.Draw(Rect(g.Size))
			b.Stroke()
			
	virtual def DrawWindowMenuButton (g as Window.MenuButton, b as Brush):
		gr = LinearGradient(0,0,0,g.Size.Height)
		if g.ContainsMouse:
			gr.Add(0, Colour(0,0.5,0))
			gr.Add(1, Colour(0,0.5,0,0.5))
		else:
			gr.Add(0, Colour(0,0.5,0,0.5))
			gr.Add(1, Colour(0,0.5,0,0))
		b.Pattern = gr
		b.Draw(Rect(g.Size))
		b.Fill()
		
		if g.ContainsMouse:
			b.Colour = Colour.Black
			b.LineWidth = 2
			b.Draw(Rect(g.Size))
			b.Stroke()
	
	virtual def DrawPanel (p as Panel, b as Brush):
		gr = LinearGradient(0,0,0,p.Size.Height)
		//gr.Add(0, Colour(0.5,0.5,0.5,0.75))
		gr.Add(0, Colour(1,0.8,0.35))
		gr.Add(1, Colour(0.5,0.5,0.5,0.75))
		
		b.Pattern = gr
		b.Draw(Rect(p.Size))
		b.Fill()
		
		gr = LinearGradient(0,0,0,p.Size.Height)
		gr.Add(0,Colour.Black)
		gr.Add(1,Colour(0,0,0,0))
		
		b.Pattern = gr
		b.LineWidth = 3
		b.Draw(Rect(p.Size))
		b.Stroke()
	
	virtual def DrawBox (g as Box, b as Brush):
		if g.DrawFrame:
			b.Colour = Colour(1,1,1,0.25)
			b.Draw(Rect(g.Size))
			b.Fill()
			b.Colour = Colour.Black
			b.LineWidth = 2
			b.Draw(Rect(g.Size))
			b.Stroke()
	
	virtual def DrawMenu (m as Menu, b as Brush):
		b.Colour = Colour(1,1,1,0.85)
		b.Draw(Rect(m.Size))
		b.Fill()
		b.Colour = Colour.Black
		b.LineWidth = 3
		b.Draw(Rect(m.Size))
		b.Stroke()
	
	virtual def DrawButtonBar (g as ButtonBar, b as Brush):
		pass
	
	virtual def DrawButtonBarButton (g as ButtonBar.Button, b as Brush):
		DrawButton(g,b)
	
	virtual def DrawVScrollerGrabby (g as VScroller.Grabby, b as Brush):
		b.Draw(Rect(g.Size))
		b.Colour = Colour.Black
		b.StrokePreserve()
		
		if g.ContainsMouse:
			b.Colour = Colour(0.75,0.75,0.00, 0.50)
		else:
			b.Colour = Colour(0.75,0.75,0.00, 0.25)
		b.Fill()
	
	override def Draw (g as Gadget, b as Brush):
		if g isa Label:
			pass
		elif g isa ButtonBar:
			DrawButtonBar(g as ButtonBar, b)
		elif g isa ButtonBar.Button:
			DrawButtonBarButton(g as ButtonBar.Button, b)
		elif g isa VScroller.Grabby:
			DrawVScrollerGrabby(g as VScroller.Grabby, b)
		elif g isa MenuItem:
			DrawMenuItem(g as MenuItem, b)
		elif g isa Menu:
			DrawMenu(g as Menu, b)
		elif g isa Window.MenuButton:
			DrawWindowMenuButton(g as Window.MenuButton, b)
		elif g isa Window.CloseButton:
			DrawWindowCloseButton(g as Window.CloseButton, b)
		elif g isa Button:
			DrawButton(g as Button, b)
		elif g isa Window:
			DrawWindow(g as Window, b)
		elif g isa Panel:
			DrawPanel(g as Panel, b)
		elif g isa Box:
			DrawBox(g as Box, b)
		else:
			DrawGadget(g, b)
